package com.sikhyeon.datastructure.model;

public class Queue {
    public static final int MAX_SIZE = 10;
    private int[] elements;
    private int front;
    private int rear;
    private int size;

    public Queue() {
        elements = new int[MAX_SIZE];
        front = 0;
        rear = -1;
        size = 0;
    }

    public void enqueue(int value) {
        if (isFull()) {
            System.out.println("Queue overflow");
        } else {
            rear = (rear + 1) % MAX_SIZE;
            elements[rear] = value;
            size++;
        }
    }

    public int dequeue() {
        if (isEmpty()) {
            System.out.println("Queue underflow");
            return -1;
        } else {
            int value = elements[front];
            front = (front + 1) % MAX_SIZE;
            size--;
            return value;
        }
    }

    public boolean isEmpty() {
        return size == 0;
    }

    public boolean isFull() {
        return size == MAX_SIZE;
    }

    public int getSize() {
        return size;
    }

    public int[] getElements() {
        int[] currentElements = new int[size];
        for (int i = 0; i < size; i++) {
            currentElements[i] = elements[(front + i) % MAX_SIZE];
        }
        return currentElements;
    }
}
